// fs流式操作


const fs = require('fs');

// 创建写入流
let ws = fs.createWriteStream('./1.txt');

//console.log(ws);
/*WriteStream {
    _writableState: WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: {
            next: null,
            entry: null,
            finish: [Function: bound onCorkedFinish]
        }
    },
    writable: true,
    domain: null,
    _events: {
        finish: {
            [Function: bound onceWrapper] listener: [Function]
        }
    },
    _eventsCount: 1,
    _maxListeners: undefined,
    path: './1.txt',
    fd: null,
    flags: 'w',
    mode: 438,
    start: undefined,
    autoClose: true,
    pos: undefined,
    bytesWritten: 0
}
*/

// 打开通道
ws.once('open', () => {
    console.log("通道已经打开");
});

// 关闭通道
ws.once('close', () => {
    console.log("通道已经关闭");
});

//写入内容
ws.write("这是写入的第一句话");
ws.write("这是写入的第二句话");
ws.write("这是写入的第三句话");

// 关闭通道
ws.end();

// 这是整个流式操作